﻿//-----------------------------------------------------------------------
// <copyright file="CategoryTests.cs" company="Transilvania University of Brasov">
//     Copyright (c) Nagy Robert. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace TestDomainModel
{
    using DomainModel;
    using Microsoft.Practices.EnterpriseLibrary.Validation;
    using NUnit.Framework;

    /// <summary>
    /// Tests for the Category class
    /// </summary>
    [TestFixture]
    public class CategoryTests
    {
        /// <summary>
        /// Gets the valid category.
        /// </summary>
        private Category ValidCategory
        {
            get
            {
                return new Category
                {
                    Id = 1,
                    Name = "Name",                    
                };
            }
        }

        /// <summary>
        /// Tests the name should not be null.
        /// </summary>
        [Test]
        public void TestNameShouldNotBeNull()
        {
            Category category = this.ValidCategory;
            category.Name = null;

            ValidationResults validationResults = Validation.Validate(category);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the name length should not be null.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestNameLengthShouldNotBeValid([Values(0, 1, 51, 100)] int length)
        {
            string name = new string('a', length);
            Category category = this.ValidCategory;
            category.Name = name;

            ValidationResults validationResults = Validation.Validate(category);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the name length should be valid.
        /// </summary>
        /// <param name="length">The length.</param>
        [Test]
        public void TestNameLengthShouldBeValid([Values(6, 25, 50)] int length)
        {
            string name = new string('a', length);
            Category category = this.ValidCategory;
            category.Name = name;

            ValidationResults validationResults = Validation.Validate(category);
            Assert.IsTrue(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the parent list should not be null.
        /// </summary>
        [Test]
        public void TestParentListShouldNotBeNull()
        {
            Category category = this.ValidCategory;
            category.ParentList = null;

            ValidationResults validationResults = Validation.Validate(category);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the parent list should initialize empty.
        /// </summary>
        [Test]
        public void TestParentListShouldInitializeEmpty()
        {
            Category category = new Category();
            Assert.AreEqual(0, category.ParentList.Count);
        }

        /// <summary>
        /// Tests the child list should not be null.
        /// </summary>
        [Test]
        public void TestChildListShouldNotBeNull()
        {
            Category category = this.ValidCategory;
            category.ChildList = null;

            ValidationResults validationResults = Validation.Validate(category);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the child list should initialize empty.
        /// </summary>
        [Test]
        public void TestChildListShouldInitializeEmpty()
        {
            Category category = new Category();
            Assert.AreEqual(0, category.ChildList.Count);
        }

        /// <summary>
        /// Tests the product list should not be null.
        /// </summary>
        [Test]
        public void TestProductListShouldNotBeNull()
        {
            Category category = this.ValidCategory;
            category.ProductList = null;

            ValidationResults validationResults = Validation.Validate(category);
            Assert.IsFalse(validationResults.IsValid);
        }

        /// <summary>
        /// Tests the product list should initialize empty.
        /// </summary>
        [Test]
        public void TestProductListShouldInitializeEmpty()
        {
            Category category = new Category();
            Assert.AreEqual(0, category.ProductList.Count);
        }
    }
}
